package com.lmmob.autotest.uitest.util;

/**
*
* @author yuanjuxing
*/
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import java.util.ArrayList;

public class SystemTime
{

   public SystemTime(){
       //time = "";
   }

   public static String getTime(){
       String time="";
       try{
           SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
           time = simpledateformat.format(new Date());
       }
       catch(Exception exception){ 
           System.err.println("exception:" + exception.getMessage()); 
      }
      return time;
   }

 public static String getCurrentTime(){
       String currenttime="";
       try{
           SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy-MM-dd_HH_mm_ss");
           currenttime = simpledateformat.format(new Date());
       }
       catch(Exception exception){ 
           System.err.println("exception:" + exception.getMessage()); 
      }
      return currenttime;
   }
   public static String getDate(){
       String time="";
       try{
           SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy-MM-dd");
           time = simpledateformat.format(new Date());
       }
       catch(Exception exception){ 
           System.err.println("exception:" + exception.getMessage()); 
      }
      return time;
   }
   /**
    * 得到几天后的时间
    * @param d
    * @param day
    * @return
    */
   public static String getDateAfter(int day){
		String time="";
	    Calendar now =Calendar.getInstance();
	    now.setTime(new Date());
	    now.set(Calendar.DATE,now.get(Calendar.DATE)+day);
	    try{
	           SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy-MM-dd");
	           time = simpledateformat.format(now.getTime());
	       }
	       catch(Exception exception){ 
	           System.err.println("exception:" + exception.getMessage()); 
	      }
	      return time;
   }
   
    public static String getDigitTime()
    {
        String currenttime="";
       try{
           SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyyMMddHHmmss");
           currenttime = simpledateformat.format(new Date());
       }
       catch(Exception exception){ 
           System.err.println("exception:" + exception.getMessage()); 
      }
      return currenttime;
    }
    public static String getMonth()
    {
        String currenttime="";
       try{
           SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyyMM");
           currenttime = simpledateformat.format(new Date());
       }
       catch(Exception exception){ 
           System.err.println("exception:" + exception.getMessage()); 
      }
      return currenttime;
    }
   public static boolean getTemp(String str1,String str2,String str3)
   {
       boolean temp = false;
       int temp1 = Integer.parseInt(str1.substring(5,7));
       int temp2 = Integer.parseInt(str2.substring(5,7));
       int temp3 = Integer.parseInt(str3.substring(5,7));
       int temp4 = Integer.parseInt(str1.substring(8,10));
       int temp5 = Integer.parseInt(str2.substring(8,10));
       int temp6 = Integer.parseInt(str3.substring(8,10));
       int temp7 = Integer.parseInt(str1.substring(0,4));
       int temp8 = Integer.parseInt(str2.substring(0,4));
       int temp9 = Integer.parseInt(str3.substring(0,4));
       if(temp7>temp8&&temp7==temp9) 
       {
           if(temp1<temp3) temp = true;
           if(temp1==temp3) 
           {
               if(temp4<=temp6) temp = true;
           }
       }
       if(temp7==temp8&&temp7==temp9)
       {
           if(temp1==temp2)
           {
              if(temp4>=temp5) temp = true;
           }
           if(temp1>temp2&&temp1<temp3) temp = true;
           if(temp1==temp3)
           {
               if(temp4<=temp6) temp = true;
           }
       }
       if(temp7==temp8&&temp7<temp9)
       {
           if(temp1>temp2) temp = true;
           if(temp1==temp2)
           {
               if(temp4>=temp5) temp = true;
           }
       }
       return temp;
   }
   
  

   public static int compute(String begin, String end){        
       SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy-MM-dd/HH:mm:ss");
        int days = 0;
       try { 
           Date date1 = simpledateformat.parse(begin); 
           Date date2 = simpledateformat.parse(end); 
          long temp = date2.getTime() - date1.getTime();
            days =(int)(temp/(1000*24*3600));    
       } 
       catch (Exception ex) { 
           System.err.println("SystemTime compute() error:" + ex.getMessage()); 
       } 
       return days;          
   }

   public static long computeSecond(String begin, String end){        
       SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy-MM-dd/HH:mm:ss");
        long second = 0;
       try { 
           Date date1 = simpledateformat.parse(begin); 
           Date date2 = simpledateformat.parse(end); 
           long temp = date2.getTime() - date1.getTime();
           second =temp/1000;    
       } 
       catch (Exception ex) { 
           System.err.println("SystemTime compute() error:" + ex.getMessage()); 
       } 
       return second;          
   }   

   public static boolean compare(String begin, String end){        
       SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy-MM-dd/HH:mm:ss");
       boolean flags=false;
       try { 
           Date date1 = simpledateformat.parse(begin); 
           Date date2 = simpledateformat.parse(end); 
          long temp = date2.getTime() - date1.getTime();
            if(temp>0)
            {
            flags=true;
            }
       } 
       catch (Exception ex) { 
           System.err.println("SystemTime compute() error:" + ex.getMessage()); 
       } 
       return flags;          
   }  
   
 //compare date  
  public static boolean comparedate(String begin, String end){        
       SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy-MM-dd");
       boolean flags=false;
        int days = 0;
       try { 
           Date date1 = simpledateformat.parse(begin); 
           Date date2 = simpledateformat.parse(end);
          // System.out.println(date1);
          // System.out.println(date2);
          long temp = date2.getTime() - date1.getTime();
           days =(int)(temp/(1000*24*3600));    
            if(days==0)
            {
            flags=true;
            }
       } 
       catch (Exception ex) { 
           System.err.println("SystemTime compute() error:" + ex.getMessage()); 
       } 
       return flags;          
   } 
  
public static boolean compareday(String begin, String end){        
       SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy-MM-dd");
       boolean flags=false;
        int days = 0;
       try { 
           Date date1 = simpledateformat.parse(begin); 
           Date date2 = simpledateformat.parse(end);
          // System.out.println(date1);
          // System.out.println(date2);
          long temp = date2.getTime() - date1.getTime();
           days =(int)(temp/(1000*24*3600));    
            if(days>=0)
            {
            flags=true;
            }
       } 
       catch (Exception ex) { 
           System.err.println("SystemTime compute() error:" + ex.getMessage()); 
       } 
       return flags;          
   }  

public static boolean sevendayslater(String begin, String end){        
       SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy-MM-dd");
       boolean flags=false;
        int days = 0;
       try { 
           Date date1 = simpledateformat.parse(begin); 
           Date date2 = simpledateformat.parse(end);
          // System.out.println(date1);
          // System.out.println(date2);
          long temp = date2.getTime() - date1.getTime();
           days =(int)(temp/(1000*24*3600));    
            if(days>=7)
            {
            flags=true;
            }
       } 
       catch (Exception ex) { 
           System.err.println("SystemTime compute() error:" + ex.getMessage()); 
       } 
       return flags;
   }

public static void main(String args[]){
	String date=SystemTime.getDateAfter(3);
	System.out.println(date);
}
 
  
}
